package com.xusj.loop

/**
  * For 循环测试
  */
object ForTest {

  def main(args: Array[String]): Unit = {

    val array = Array("a", "b", "c", "d", "e", "f")

    //集合操作
    for (arr <- array) {
      println("arr:%s".format(arr))
    }

    //间接操作
    for (i <- 0 to array.length - 1) {
      println("arr:%s".format(array(i)))
    }

    // 高级用法
    val arrs = 1 to 5

    println("针对 arrs中奇数* 10 生成新的集合")
    val arrRet = for (arr <- arrs if arr % 2 != 0) yield arr * 10

    println(arrRet)

    println("for 循环嵌套")
    for (i <- "abc"; j <- "xyz") println(s"$i + $j")
  }
}
